import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/pages/index/Index'
import Category from '@/pages/category/Category';
import Product from '@/pages/product/Product';
import Cart from '@/pages/cart/Cart';
import My from '@/pages/my/My';

Vue.use(Router)


// 路由表
const Routers = [{
        path: '/',
        name: 'Index',
        component: Index,
        meta: {
            title: '首页'
        }
    },
    {
        path: '/category',
        redirect: '/category/55'
    },
    {
        path: '/category/:id',
        name: 'Category',
        component: Category,
        meta: {
            title: '分类页'
        }
    },
    {
        path: '/product/:id',
        name: 'Product',
        component: Product,
        meta: {
            title: '产品详情'
        }
    },
    {
        path: '/cart',
        name: 'Cart',
        component: Cart,
        meta: {
            title: '购物车'
        }
    },
    {
        path: '/my',
        name: 'My',
        component: My,
        meta: {
            title: '我的'
        }
    },
    {
        path: '*',
        redirect: '/'
    }
];

// 路由配置信息
const RouterConfig = {
    linkActiveClass: 'active',
    linkExactActiveClass: 'nav-item',
    mode: 'hash',
    routes: Routers
};

const router = new Router(RouterConfig);

router.beforeEach((to, from, next) => {
    // 修改标题
    window.document.title = to.meta.title;
    next()

})


export default router;